clear all
set more off
version 14.0


		
	
*------------------------------------------------------------------
* Damages RCP 4.5
*------------------------------------------------------------------
use "..\temp\damages_irr_total_rcp45AVG", clear
ren chg_rent chg_rent_total
ren ln_chg_rent ln_chg_rent_total
ren damages damages_total
ren perc_chg_rent perc_chg_rent_total
foreach j in deficit surplus heat {
		merge 1:1 stcofips using "..\temp\damages_irr_`j'_rcp45AVG", nogen
		ren chg_rent chg_rent_`j'
		ren ln_chg_rent ln_chg_rent_`j'
		ren damages damages_`j'
		ren perc_chg_rent perc_chg_rent_`j'
	}
cap drop  __00*  // drop any temporary variables //	

/*
gen prop_netppt_dd=chg_rent_netppt/chg_rent_netppt_dd if chg_rent_netppt<0 & chg_rent_dd<0

summ prop_netppt_dd, detail

gen proportion=.
replace proportion=1 if chg_rent_netppt<0 & chg_rent_dd>0 & chg_rent_netppt!=. & chg_rent_dd!=.
replace proportion=2 if prop_netppt_dd>=0.75 & prop_netppt_dd<1
replace proportion=3 if prop_netppt_dd>=0.5 & prop_netppt_dd<0.75
replace proportion=4 if prop_netppt_dd>=0.25 & prop_netppt_dd<0.5
replace proportion=5 if prop_netppt_dd>=0 & prop_netppt_dd<0.25
replace proportion=6 if chg_rent_netppt>0 & chg_rent_dd<0 & chg_rent_netppt!=. & chg_rent_dd!=.
replace proportion=7 if chg_rent_netppt>0 & chg_rent_dd>0 & chg_rent_netppt!=. & chg_rent_dd!=.

label define plabel 1 "Only netppt has negative effect" 2 "1 > Proportion netppt > 0.75" ///
				3 "0.75 > Proportion netppt > 0.5" 4 "0.5 > Proportion netppt > 0.25" 5 "0.25 > Proportion netppt > 0" ///
				6 "Only dd has negative effect" 7 "Neither have negative effect" 
label values proportion plabel
*/

rename stfips stfip
rename cofips cofip
merge 1:1 stfip cofip using "../maps/county_db_my_region2", keep(match using) nogen

* Drop counties in SW New Mexixo and Texas to allow room for the legend
drop if stcofips==35023 | stcofips==35017 | stcofips==35029 | stcofips==35013 | stcofips==48141 | stcofips==35035 ///
		 | stcofips==35051 | stcofips==48229 

summ perc_chg_rent_total, detail
format perc_chg_rent_total %9.2f
spmap perc_chg_rent_total using "../maps/county_coord_my_region2", id(id) ocolor(none ..) ndocolor(none ..)  ///
			polygon(data("../maps/state_coord_my_region2") ocolor(gs14) osize(medthick))  ///
			fcolor("179 0 0" "227 74 51" "252 141 89" "253 187 132" "253 212 158" "254 240 217" ///
			"255 255 204" "194 230 153" ) ///
			ndf(white) ndlabel(" ") legorder(lohi) ///
			legend(position(8) size(3.5)) title("Total") ///
			plotregion(margin(l=7 r=2 t-5)) ///
			clm(custom) clbreaks(-0.73 -0.65 -0.50 -0.35 -0.25 -0.15 0 0.3 1.16) name(perc_chg_rent_total, replace)
*graph export "../figures/perc_chg_rent_total_irr.png", replace	width(1200)

summ perc_chg_rent_deficit, detail
format perc_chg_rent_deficit %9.2f
spmap perc_chg_rent_deficit using "../maps/county_coord_my_region2", id(id) ocolor(none ..) ndocolor(none ..) ///
			polygon(data("../maps/state_coord_my_region2") ocolor(gs14) osize(mthick)) ///
			fcolor("255 255 204" "194 230 153") ///
			ndf(white) ndlabel(" ") legorder(lohi) ///
			legend(position(8) size(3.5)) title("Water Deficit") ///
			plotregion(margin(l=7 r=2 t-5)) ///
			clm(custom) clbreaks(0 0.02 0.04) name(perc_chg_rent_deficit, replace)
*graph export "../figures/perc_chg_rent_deficit_irr.png", replace	width(1200)	

summ perc_chg_rent_surplus, detail
format perc_chg_rent_surplus %9.2f
spmap perc_chg_rent_surplus using "../maps/county_coord_my_region2", id(id) ocolor(none ..) ndocolor(none ..) ///
			polygon(data("../maps/state_coord_my_region2") ocolor(gs14) osize(mthick)) ///
			fcolor( "254 240 217" ///
			"255 255 204" "194 230 153") ///
			ndf(white) ndlabel(" ") legorder(lohi) ///
			legend(position(8) size(3.5)) title("Water Surplus") ///
			plotregion(margin(l=7 r=2 t-5)) ///
			clm(custom) clbreaks(-0.03 0 0.01 ) name(perc_chg_rent_surplus, replace)
*graph export "../figures/perc_chg_rent_surplus_irr.png", replace	width(1200)	
			
summ perc_chg_rent_heat, detail
format perc_chg_rent_heat %9.2f
spmap perc_chg_rent_heat using "../maps/county_coord_my_region2", id(id) ocolor(none ..) ndocolor(none ..) ///
			polygon(data("../maps/state_coord_my_region2") ocolor(gs14) osize(mthick)) ///
			fcolor("179 0 0" "227 74 51" "252 141 89" "253 187 132" "253 212 158" "254 240 217" ///
			"255 255 204" "194 230 153" "120 198 121" "35 132 67") ///
			ndf(white) ndlabel(" ") legorder(lohi)  ///
			legend(position(8) size(3.5)) title("Heat Stress") ///
			plotregion(margin(l=7 r=2 t-5)) ///
			clm(custom) clbreaks(-0.73 -0.55 -0.4 -0.3 -0.2 -0.1 0 0.5 0.94) name(perc_chg_rent_heat, replace)
*graph export "../figures/perc_chg_rent_heat_irr.png", replace	width(1200)	


*------------------------------------
* Combine graphs
*-------------------------------------
graph combine perc_chg_rent_total perc_chg_rent_deficit perc_chg_rent_surplus perc_chg_rent_heat, ///
		cols(2) imargin(vsmall) iscale(*1.27) graphregion(color(white)) altshrink ysize(4) xsize(5)
*graph combine perc_chg_rent_total perc_chg_rent_deficit perc_chg_rent_surplus perc_chg_rent_heat, ///
*		cols(4) imargin(vsmall) iscale(*1.27) graphregion(color(white)) altshrink ysize(2.25) xsize(7.5)

graph export "..\figures\perc_chg_rent_combined_irr.png", replace	width(1600)	
